/* 这是个监听工具，监控main.js触发的组播数据包，由于ESP32实际上利用UDP包长度传递SSID和PWD， */
const dgram = require('dgram');
const client = dgram.createSocket('udp4');
const multicastAddr = '234.100.100.100';

client.on('close', () => {
    console.log('socket已关闭');
});

client.on('error', (err) => {
    console.log(err);
});
client.on('listening', () => {
    console.log('socket正在监听中...');
    // for (let i = 1; i < 101; i++) {
    //     client.addMembership(`234.${i}.${i}.${i}`);
    // };
    client.addMembership(`234.10.10.10`);
    const address = client.address()
    console.log(`client listening ${address.address}:${address.port}`)

});
client.on('message', (msg, rinfo) => {
    //console.log(`receive server message from ${rinfo.address}:${rinfo.port}：${msg.length}`);
    console.log(`${msg.length}`); //只监听包长度即可
});
client.bind(7001); // 此处必须绑定自己的局域网IP或者不填，填localhost是不行的，建议不填

